﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Simple.Common.AutoMapper;

namespace GRPC.Service.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            var Id = Guid.NewGuid();
            var item1 = new FatherClass()
            {
                Id =Id,
                Count = 1,
                ChildClasses = new List<ChildClass>()
                {
                    new ChildClass()
                    {
                        FatherClassId = Id,
                        Name = "小明"
                    },
                    new ChildClass()
                    {
                        FatherClassId = Id,
                        Name = "小红"
                    }
                }
            };
            var t = item1.ChildClasses.Map<ChildClass>();

            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            })
            .ToArray();
        }
    }

    public class FatherClass
    {
        public  Guid Id { get; set; }=Guid.NewGuid();
        public int Count { get; set; }

        public List<ChildClass> ChildClasses { get; set; }
        private void Check()
        {
            return;
        }
    }

    public class ChildClass
    {
        public Guid Id { get; set; }=Guid.NewGuid();
        public Guid FatherClassId { get; set; }
        public string Name { get; set; }
    }

    public class OthenFatherClass : FatherClass
    {
        private string _otherName;

        public string OtherName
        {
            get => _otherName;
            set => _otherName = value+1;
        }
    }
}
